package study.java.jdk.jdk8._3_comparator.comparing;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import study.java.jdk.jdk8.User;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Slf4j
public class _1_comparingTest {

    static List<User> userLt;

    static {
        User u1 = new User("1003");
        User u2 = new User("1002");
        User u3 = new User("1001");
        userLt = Arrays.asList(u1, u2, u3);
    }

    /**
     * 自然顺序（升序）
     *
     * @param keyExtractor Function（key提取器）
     */
    @Test
    public void test() {
        Comparator<User> comparator = Comparator.comparing(User::getCode);
        //
        Collections.sort(userLt, comparator);
        userLt.forEach(d -> {
            log.info(">>>>>> {}", d.getCode());
        });
    }
}
